package com.zmn.plat.admin.controller.channel.tariff;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.plat.manager.dictionary.ChannelDict;
import com.zmn.plat.model.entity.channel.Channel;
import com.zmn.plat.model.entity.channel.ChannelQuery;
import com.zmn.plat.model.entity.channel.tariff.ChannelTariffQuery;
import com.zmn.plat.model.entity.service.tariff.ServiceTariff;
import com.zmn.plat.model.vo.channel.tariff.ChannelTariffVo;

/**
 * 价格表使用渠道关联表
 *
 * @author linfeng
 *
 * @since 2020-03-03 10:10:14
 */
@Controller
@RequestMapping("/channel/tariff/")
public class ChannelTariffListController extends ChannelTariffBaseController {

    /**
     * 列表
     * 
     * @author linfeng
     * @param query
     * @since 2020-03-03 10:10:14
     */
    @RequestMapping("list")
    @RequiresPermissions("/channel/tariff/list.action")
    public ModelAndView list(@ModelAttribute ChannelTariffQuery query) {

        List<ChannelTariffVo> items = channelTariffService.listPageByQuery(query);
        ChannelQuery channelQuery = new ChannelQuery();
        channelQuery.setRank(ChannelDict.RANK_ONE);
        List<Channel> channelLevelOnes = channelService.listByQuery(channelQuery);
        ServiceTariff tariff = faultTariffService.findByKey(query.getTariffId());

        ModelAndView mav = new ModelAndView("channel/tariff/list");
        mav.addObject("items", items);
        mav.addObject("vo", query);
        mav.addObject("faultTariff", tariff);
        mav.addObject("flag", query.getFlag());
        mav.addObject("channelLevelOnes", channelLevelOnes);
        return mav;
    }

    /**
     * 新增按钮下的列表：选择没有使用该价格表的二级渠道
     * 
     * @author linfeng
     * @param query
     * @since 2020-03-03 10:10:14
     */
    @RequestMapping("listAjax")
    @RequiresPermissions("/channel/tariff/listAjax.action")
    public ModelAndView listAjax(@ModelAttribute ChannelTariffQuery query) {
        List<ChannelTariffVo> items = channelTariffService.listAjaxPageByQuery(query);
        ChannelQuery channelQuery = new ChannelQuery();
        channelQuery.setRank(ChannelDict.RANK_ONE);
        List<Channel> channelLevelOnes = channelService.listByQuery(channelQuery);

        ModelAndView mav = new ModelAndView("channel/tariff/select/list");
        mav.addObject("items", items);
        mav.addObject("vo", query);
        mav.addObject("plats", GlobalConsts.getPlatList());
        mav.addObject("channelLevelOnes", channelLevelOnes);
        return mav;
    }

}
